package cs5226.tags;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import cs5226.util.*;
import cs5226.model.*;

public class LoggedIn extends SimpleTagSupport {

	private String statistics;

	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		
		PageContext pc = (PageContext) getJspContext();
		HttpServletRequest request = (HttpServletRequest) pc.getRequest();
		String userId = (String) request.getSession().getAttribute("loggedIn"); //request.getRemoteUser();
		
		if (StringUtil.isNullOrBlank(userId)) {
			out.println (" <a href='login'>Login</a>");
		}
		else {
			out.println("Welcome " + userId + " | <a href='logout'>Logout</a>");
		}
		
		out.println (String.format(" | %1$td-%1$tB-%1$tY %1$tR", new Date()));
		
	}

	public String getStatistics() {
		return statistics;
	}

	public void setStatistics(String statistics) {
		this.statistics = statistics;
	}

}
